﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Hopscotch.Common.Logging;

namespace Hopscotch.Application.EnqServer
{
    class Program
    {
        static readonly ILogger logger = AppLogger.CreateLogger("EnqServer");

        static void Main(string[] args)
        {
            logger.Info("Starting Enquiry Server...");

            IUnityContainer container = new UnityContainer();
            UnityConfiguration.ConfigureContainer(container);

            if (Environment.UserInteractive)
            {
                StartInteractive(container);
            }
            else
            {
                //ServiceBase.Run(new WindowsService());
            }
        }

        private static void StartInteractive(IUnityContainer container)
        {
            using (var signalRStartup = new SignalRManager(container))
            {
                signalRStartup.Start();

                logger.Info("Enquiry Server Started.");

                RunLoop();
            }
        }

        private static void RunLoop()
        {
            while (true)
            {
                Console.WriteLine("Server running...");
                Console.WriteLine("Press <q> to quit");
                ConsoleKeyInfo ki = Console.ReadKey(true);

                if (ki.Key == ConsoleKey.Q)
                {
                    break;
                }
            }
        }

    }
}
